<template>
  <div
    v-loading="isLoading"
    class="panel-data"
  >
    <div class="content">
      <el-form
        ref="form"
        class="prop-form"
        label-position="right"
        :model="form"
        label-width="82px"
      >
        <TooltipEditor
          :btn-text="btnText"
          :config="config"
          :vars="{}"
          :extra-config="extraConfig"
          use-for="hover-text"
          @save="saveTooltip"
        />
      </el-form>
    </div>
  </div>
</template>
<script>
import TooltipEditor from '@/components/common/tooltip/tooltip-editor.vue';
import xTagBase from '@/components/panel-data/xtag-base.js';

/**
 * config  整体配置项
 */
const xMiner = 'xMiner';
const xTag = 'xTag';
export default {
  name: 'PanelData',
  components: {
    TooltipEditor,
  },
  mixins: [xTagBase],
  props: ['config', 'widgetInstanceId'],
  data() {
    return {
      xMiner,
      xTag,
      xvueTheme: window._adoPremise.uc.theme,
      selectStyle: {
        maxWidth: '',
      },
      mappingOptions: [],
      dataTableList: [],
      dataSourceList: [],
      apiList: [],
      isLoading: false,
      propertyData: this.property,
      form: {},
      btnText: this.$demoi18n('panel.btn.textContentSetting'),
      extraConfig: {
        position: 'panel-data',
      },
    };
  },
  computed: {
    activeColorSwitch() {
      switch (this.xvueTheme) {
        case 'dark':
          return '#0EB4C2';
        default:
          return '#00AAFF';
      }
    },
    inactiveColorSwitch() {
      switch (this.xvueTheme) {
        case 'dark':
          return '#064559';
        default:
          return '#C0CCDA';
      }
    },
  },
  created() {
    if (this.config) {
      const dataConfig = JSON.parse(JSON.stringify(this.config.config.data));
      this.loadData(dataConfig);
    }
  },
  methods: {
    loadData(dataConfig) {
      this.form.tooltip = dataConfig.tooltip;
    },
    saveTooltip(tooltip) {
      this.form.tooltip = tooltip;
    },

    // 设置下拉option的title属性
    setTagTitle($event) {
      if (!$event) {
        return;
      }
      const dropdownList = document.querySelectorAll('.el-select-dropdown');
      dropdownList.forEach(item => {
        const options = item.querySelectorAll('.el-select-dropdown__item');
        options.forEach(element => {
          element.setAttribute('title', element.innerText);
        });
      });
    },

    // 设置 下拉option 的最大宽度
    setMaxWidth(val) {
      // this.selectStyle.maxWidth = `${val.srcElement.clientWidth}px`;
    },
  },
};
</script>
<style lang="less" scoped>
.panel-data {
  .content {
    padding: 0 10px;
    .prop-form {
      text-align: center;
      :deep(.el-form-item) {
        margin-bottom: 0;
      }

      :deep(.xtag-dataTable-select) {
        width: 129px;
        padding-right: 8px;
      }
      .input-number {
        width: 80px;
        :deep(.el-input-number__decrease) {
          width: 19px;
        }
        :deep(.el-input-number__increase) {
          width: 19px;
        }
        :deep(.el-input__inner) {
          padding-left: 19px;
          padding-right: 19px;
        }
      }
      .input-number-left {
        margin-right: 25px;
      }

      .color-radio-group {
        background-color: #eeeeee;
        :deep(.el-radio-button__inner) {
          display: inline-block;
          padding: 2px 2px;
          border: 0;
          border-radius: 0;
          height: 24px;
          margin: 2px 2px;
          background: #eeeeee;
        }
        :deep(.is-active) {
          .el-radio-button__inner {
            background-color: #409eff;
          }
        }
      }
    }

    .container {
      .preview {
        background-color: #f7f7f7;
      }
    }

    .markLine {
      .switch {
        padding-top: 15px;
        .text {
          font-size: 14px;
          padding-right: 10px;
          height: 28px;
          line-height: 28px;
        }
        .value {
          display: inline-block;
          width: 150px;
          margin-left: 10px;
        }
      }
    }
  }
}
</style>

<style lang="less">
.panel-data-select-dark {
  :deep(.el-input) {
    .el-input__inner {
      border-color: #588ba8;
      color: #fff;
      background-color: #091a2d;
    }
    .el-input__icon {
      color: #588ba8;
    }
  }
}

.select-poper-dark {
  background-color: #091a2d;
  border-color: #588ba8;

  :deep(.el-scrollbar) {
    .el-select-dropdown__list {
      .el-select-dropdown__item {
        padding: 0 12px;
        height: 24px;
        line-height: 24px;
        font-size: 12px;
        color: #fff;
        background-color: #091a2d;

        .select-icon {
          padding: 0;
        }

        .select-option-slot-text {
          display: inline-block;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
          color: #178ddf;
        }
        .select-option-slot-icon {
          display: inline-block;
          vertical-align: top;
        }
        .select-option-slot-icon-edit {
          float: right;
        }
      }
      .hover {
        background-color: #102e4f;
      }
    }
  }
  :deep(.popper__arrow) {
    border-bottom-color: #588ba8;
    &::after {
      border-bottom-color: #091a2d !important;
    }
  }
}

.select-poper-light {
  :deep(.el-scrollbar) {
    .el-select-dropdown__list {
      .el-select-dropdown__item {
        padding: 0 12px;
        height: 24px;
        line-height: 24px;
        font-size: 12px;
        .select-icon {
          padding: 0;
        }

        .select-option-slot-text {
          display: inline-block;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
        .select-option-slot-icon {
          display: inline-block;
          vertical-align: top;
        }
        .select-option-slot-icon-edit {
          float: right;
        }
      }
    }
  }
}
</style>
